{# TODO(ppershing): make title, description, chart, histogram and comments as parameters #}
{% macro displayResults(data, season) %}
    <h2 class="fragment" id="otazka{{ data.id }}"> <a href="#otazka{{ data.id }}">{{ data.title }}</a> </h2>
    <div>
    {# nasledujuci if je nutny, lebo aj polozka pola je null, twig hadze
        Item "description" for "Array" does not exist #}
    {% if data.description is defined %}
        <p class="question-description">{{ data.description }}</p>
    {% endif %}
    </div>
    {% if not data.hasAnswer and data.numberOfInappropriateComments == 0 %}
        {{ trans('statistics.displayQuestionMacro.nik_neodpovedal') }}
    {% else %}
        {% if data.chart is not null %}
            <img src="{{ data.chart.url }}" width="{{ data.chart.width }}" height="{{ data.chart.height }}" alt="">
        {% endif %}
        {% if data.histogram is not empty %}
            <div class="stats-details">
                <table>
                    <thead>
                        <tr>
                            <th> {{ trans('statistics.displayQuestionMacro.moznost') }} </th>
                            <th> {{ trans('statistics.displayQuestionMacro.hlasov') }} </th>
                            <th> {{ trans('statistics.displayQuestionMacro.podiel') }} </th>
                            {% if data.hasDifferentOptions %}
                            <th> <span title="{{ trans('statistics.displayQuestionMacro.vaha_pre_statistiku') }}" class="help-tooltip">
                                {{- trans('statistics.displayQuestionMacro.v') -}}
                            </span> </th>
                            {% endif %}
                        </tr>
                    </thead>
                    {% for row in data.histogram %}
                        <tr>
                            <td> {{ row.title }} </td>
                            <td class="numeric"> {{ row.cnt }} </td>
                            <td class="numeric"> {{ "%.0f" | format(row.portion*100) }}% </td>
                            {% if data.hasDifferentOptions %}
                                <td class="numeric"> {{ row.value }} </td>
                            {% endif %}
                        </tr>
                    {% endfor %}
                </table>
                <ul>
                    <li data-cnt="{{ data.stats.cnt }}">{{ trans('statistics.displayQuestionMacro.pocet_hlasov') }}: {{ data.stats.cnt }} </li>
                    {% if data.stats.avg is defined %} 
                        <li data-avg="{{ "%.2f" | format(data.stats.avg) }}">
                            {{ trans('statistics.displayQuestionMacro.priemer') }}: {{ "%.2f" | format(data.stats.avg) }}
                        </li>
                    {% endif %}
                    {% if data.stats.median is defined %}
                        <li>{{ trans('statistics.displayQuestionMacro.median') }}: {{ "%.2f" | format(data.stats.median) }} </li>
                    {% endif %}
                    {% if data.stats.sigma is defined %} 
                        <li>{{ trans('statistics.displayQuestionMacro.odchylka') }}: {{ "%.2f" | format(data.stats.sigma) }} </li>
                    {% endif %}
                </ul>
            </div>
        {% endif %}
        {% if data.commentsAllowed %}
            {% if access.statistics.canSeeComments(season) %}
                {% if data.comments is not empty %}
                    {{ trans('statistics.displayQuestionMacro.komentare') }}:
                    <div class="results-comments">
                    {% for comment in data.comments %}
                        <div class='comment' id="komentar{{ comment.answer_id }}">
                        <div class="comment-top"><a class="comment-link" href="#komentar{{ comment.answer_id }}">#{{ comment.answer_id }}</a>:
                            <a href="{{ path('statistics_flag', {'answer_id': comment.answer_id}) }}" class="flag-link">
                                {{- trans('statistics.displayQuestionMacro.nahlasit_komentar') -}}
                            </a>
                        </div>
                        <p class="comment-comment">{{ comment.comment|escape|replace({"\n":"<br>"})|raw }}</p>
                        </div>
                    {% endfor %}
                    </div>
                {% elseif data.numberOfInappropriateComments == 0 %}
                    {{ trans('statistics.displayQuestionMacro.ziaden_komentar') }}
                {% endif %}
                {% if data.numberOfInappropriateComments > 0 %}
                    <p class="inappropriate-comments-info">
                    {{- trans('statistics.displayQuestionMacro.skryte_komentare', {'%count%': data.numberOfInappropriateComments}, data.numberOfInappropriateComments) -}}
                    </p>
                {% endif %}
            {% elseif access.statistics.getUser %}
                {% trans %}statistics.displayQuestionMacro.komentare_nepristupne{% endtrans %}
            {% else %}
                {{ trans('statistics.displayQuestionMacro.komentare_po_prihlaseni', {'%url%': path('login', {'to': app.request.uri}) }) }}
            {% endif %}
        {% endif %}
    {% endif %}

{% endmacro %}
